import 'package:flutter/material.dart';
import 'package:flutter_plugin/ext/get_extension.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../res/style.dart';

/// @description :成功或失败
class SuccessFailDialog extends StatelessWidget {
  ///内容
  String content = '';

  ///成功1，失败2
  int dialogTyle = 1;

  /// 消失回调
  VoidCallback? disappearCallBack;

  SuccessFailDialog({
    Key? key,
    this.content = '请求成功',
    this.dialogTyle = 1,
    this.disappearCallBack,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    /// 1秒后消失，回调disappearCallBack()
    Future.delayed(const Duration(seconds: 1), () {
      if (Get.isDialogOpen != null && Get.isDialogOpen!) {
        Get.dismiss();
        if (disappearCallBack != null) {
          disappearCallBack!();
        }
      }
    });

    return Material(
      ///透明样式
      type: MaterialType.transparency,

      ///dialog居中
      child: Center(
        ///取消ListView滑动阴影
        child: ListView(
          shrinkWrap: true,
          children: [
            ///背景及内容、边距、圆角等，必须包裹在ListView中
            Container(
              width: double.infinity,
              margin: EdgeInsets.symmetric(
                horizontal: 53.w,
              ),
              decoration: const ShapeDecoration(
                color: Colors.white,
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(
                    Radius.circular(20.0),
                  ),
                ),
              ),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Box.hBox20,
                  Image.asset(
                    "assets/images/alert_sucess.png",
                    width: 38.w,
                    height: 38.h,
                  ),
                  // DividerStyle.dividerHalf,
                  Box.hBox15,
                  Text(
                    content,
                    style: Styles.style_black_16_bold,
                  ),
                  Box.hBox17,
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
